MODULE definitions

  IMPLICIT NONE

  TYPE :: CELL

     REAL :: SurfaceVegetation
     REAL :: xwindspeed, ywindspeed
     REAL :: Slabnumber

  END TYPE CELL

  TYPE :: DECK

     INTEGER, DIMENSION(2) :: entry

  END TYPE DECK

  TYPE(CELL), DIMENSION(:,:), ALLOCATABLE 	:: Sandpit !Definition of the grid to be simulated
  
  TYPE(DECK), DIMENSION(:), ALLOCATABLE :: position
  
  REAL, DIMENSION(:,:), ALLOCATABLE :: sliced_transport_length, sliced_erosion_hight, &
       sliced_average_hight, sliced_average_flux, local_transport_length, local_eroded_hight, &
       local_deposited_hight, local_aeolian_flux, local_avalanche_flux, local_sediment_balance, &
       local_max_hight, sliced_covered_cells
  REAL, DIMENSION(:), ALLOCATABLE :: max_hight

  REAL	:: pi = 3.14159265
  INTEGER :: load = 0		!Switch to choose initialisation mod.
  INTEGER :: qifconv = 0
  INTEGER :: slices = 0
  INTEGER :: full = 0
  INTEGER :: debtimer = 0       !switch to turn on timer for optimisation  
  INTEGER :: xsink = 1          !turn xboundary sink on or of
  INTEGER :: ysink = 0          !turn yboundary sink on or of
  INTEGER :: ylock = 0
  INTEGER :: source = 1         !Source on or of
  INTEGER :: sourceeq = 0       !Inflow according to outflow
  INTEGER :: eshadow = 1        !Switch to turn on shadow zones for erosion and deposition
  INTEGER :: dshadow = 0        !set to ON by default
  INTEGER :: recaval = 0        !Switch for recursive avalanches, set to ON by default
  INTEGER :: gradS = 0          !Switch for gradient in sediment source
  INTEGER :: gradE = 0          !Switch for gradient in eroded sediment on cell
  INTEGER :: gradL = 0
  
  INTEGER :: seed	        !Seed for random numbers generator
  INTEGER :: steps		!Maximum interation steps
  INTEGER :: frames		!Number of frames for output
  
  INTEGER :: xsize		!Size of the grid in x direction
  INTEGER :: ysize		!Size of the grid in y direction
  
  REAL	:: slabsize = 1		!Size of one slab in x and y direction  
  REAL	:: windx		!Wind velocity in x and y direction
  REAL	:: windy		!for use of arbitrary wind directions and shadow
  REAL  :: L0 = 4                  !lower mean transport length
  REAL  :: L1 = 4                  !multiple of lower mean transport lengt on upper end of array for gradL = 1   
  REAL  :: E0 = 0.3
  REAL  :: E1 = 0.3
  REAL  :: ncov
  REAL  :: par1 = 0.9           !parametrisation of erosion dep. on slope
  REAL  :: par2 = 1             !parametrisation of deposition dep. on slope
  
  REAL	:: maxangle = 34	!Trigger angle for avalanche	
  REAL	:: minangle = 30	!Angle of repose
  REAL	:: maxslope
  
  REAL :: initialhight	        !Initial hight of the simulated array
  REAL :: sourceflow            !Flow from source per iteration per boundary cell in slabsize² * sourceflow
  REAL :: sourceflow1
  REAL :: sourcebuf = 0, xsinkbuf = 0, erbuf = 0
  INTEGER :: avalcount, eshadowcount, dshadowcount, empty, pn, stackcount, timer, qtrig=0, count1, &
       count2, countrate, countmax, tconv
  REAL :: mintl, maxtl, mineh, maxeh, mindh, maxdh, minaf, maxaf, minvf, &
       maxvf, minsb, maxsb, avhightbuf, dwflux=0, daflux=0

  INTEGER, PARAMETER :: out1 = 11, out2 = 12, out3 = 13, out4 = 14, &
       out5 = 15, out6 = 16, out7 = 17, out8 = 18, out9 = 19, &
       out10 = 22, out11 = 23, out20 = 20, out21 = 21
  INTEGER, PARAMETER :: in1 = 31, in2 = 32, in3 = 33, in4 = 34
  
  INTEGER, DIMENSION(2,8) :: relpos ! respos(1,:) for x and relpos(2,:) for y position
  INTEGER, DIMENSION(0:5000) :: path
  
  NAMELIST /PARAMETER/ load, qifconv, slices, full, debtimer, xsink, ysink, ylock, source, &
       sourceeq, eshadow, dshadow, recaval, gradS, gradE, gradL,  seed, steps,&
       frames, xsize, ysize, slabsize, windx, windy, L0, L1, E0, E1, ncov, par1, par2, maxangle,&
       minangle, initialhight, sourceflow, sourceflow1

CONTAINS

END MODULE Definitions
